﻿Global.namespace("System.Web.Handler");
System.Web.Handler.MessageHandler=function(){}
System.Web.Handler.MessageHandler.sendGifts=function(config){
    try{
        var url=StringHandler.format(
            '{0}inlineService.axd?action=sendgift&receiverId={1}&gift={2}&message={3}&t={4}',
            Config.rootServiceURL,
            config.receiverId,
            config.gift,
            escape(config.message),
            Global.random()
        );
    
        System.Core.Handler.RequestHandler.get(
            url,
            {},
            function(response){
                if(!config.callback){ return;}
                var data=System.Core.Handler.RequestHandler.getResponseData(response);
                data=StringHandler.format('({0})',data);
                config.callback(eval(data));
            }
        );
    
    }catch(e){
        alert(e.message);
    }
}
System.Web.Handler.MessageHandler.sendInvitation=function(receiverId, strMessage, callback){
    //check permission for this viewer
    if(!opensocial.hasPermission(opensocial.Permission.VIEWER)) { return;}
    //after call opensocial.requestShareApp function, opensocial will handle all event
    var message = opensocial.newMessage(strMessage);
    opensocial.requestShareApp(
        receiverId,
        message,
        function(){
            callback();
        }
    );
}

